<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2018\10\28 0028
 * Time: 10:03
 */
namespace app\admin\controller;
use app\admin\model\Commons;
use app\admin\model\GetPassword;
use think\Db;
use think\Request;

class Land
{
    public function admin(Request $request){
        $admin_user = $request->param('user',null);
        $admin_pwd  = $request->param('pwd',null);
        if(!$admin_user){
            return '请输入账号';
        }
        if(!$admin_pwd){
            return '请输入密码';
        }
        //return $admin_pwd;
        $data = Db::name('admin')->where('username',$admin_user)->find();
//        return json($data);
        if(!$data){
            return '账号不存在';
        }
        if($admin_user===$data['username']&&Commons::getPassword
            ($admin_pwd)===$data['password']){
            Db::name('admin')->where('username',$admin_user)->update(['last_login_time'=>time(),'last_login_ip'=>$_SERVER['REMOTE_ADDR']]);
            session('adminuser',$data);
            return 1;
        }else{
            return '账号或密码错误';
        }
    }
}